AddMenu = function() {
	return {
		submitForm : function() {
			if(!$('#menuForm').form('validate')) {
				return;
			}
			var status = $("#status").combobox('getValue');
			if(null == status || "" == status) {
				Ict.warn("请选择菜单状态!");
				return;
			}
			var companyId = $("#company").combotree('getValue');
			$("#companyId").val(companyId);
			$('#menuForm').form('submit', {
				url      : "/pc/menu/saveMenuInfo.htm",
				onSubmit : function() {
					return $('#menuForm').form('validate');
				},
				success  : function(data) {
					if(data == "SUCCESS") {
						Ict.info("保存成功!", function() {
							Ict.closeWin();
							$("#menuTree").treegrid('reload');
			    		});
					} else {
						Ict.warn("保存失败!");
					}
				}
			});
		}
	};
}();

$(function(){
	$("#parentId").combotree({
		url      : '/pc/menu/comboTree.htm',
		editable : false,
		required : true,
		onLoadSuccess : function() {
			var row = $('#menuTree').treegrid('getSelections');
			if(0 == row.length) {
				$('#parentId').combotree('setValue', "0");
				$('#parentId').combotree('enable', true);
			} else {
				$('#parentId').combotree('setValue', row[0].id);
			}
		},
		onSelect : function(node) {
			if(0 != node.id) {
				$.ajax({
					url     : '/pc/menu/getCompIdByMenuId.htm?menuId=' + node.id,
					type    : 'POST',
					success : function(data) {
						$("#company").combotree('setValue', data);
						$("#company").combotree('disable', true);
					}
				});
			} else {
				$("#company").combotree('enable', true);
			}
		}
	});
	
	$("#company").combotree({
		url       : '/pc/company/tree.htm',
		editable  : false,
		required  : true,
		idField   : 'id',
		treeField : 'text'
	});
	
	$("#status").combobox({
		editable      : false,
		required      : true,
		panelHeight   : 'auto',
		onLoadSuccess : function() {
			$("#status").combobox('setValue', "");
		}
	});
	
	$("#displayOrder").numberspinner({
		editable : false,
		width    : 280
	});
});